package com.hongxun.design.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hongxun.design.R;
import com.hongxun.design.bean.TransFormerMaterialBean;

import java.util.List;

/**
 * Created by zerdoor_pc on 2016/6/6.
 */
public class MaterialAdapter extends BaseAdapter {
    Context context;
    List<TransFormerMaterialBean> listBeans;
    LayoutInflater inflater;

    public MaterialAdapter(Context context, List<TransFormerMaterialBean> listBeans) {
        this.context = context;
        this.listBeans = listBeans;
        if (context!=null) inflater = LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return listBeans.size();
    }

    @Override
    public Object getItem(int i) {
        return listBeans.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holldler holldler = null;
        if (view == null) {
            view = inflater.inflate(R.layout.listview_item_material, null);
            holldler = new Holldler(view);
            view.setTag(holldler);
        } else {
            holldler = (Holldler) view.getTag();
        }
        TransFormerMaterialBean bean;
        try {
            bean = listBeans.get(i);

            holldler.name.setText(bean.getName());
            holldler.spec.setText(bean.getSpec());
            holldler.unit.setText(bean.getUnit());
            holldler.num.setText(bean.getNum());
        } catch (Exception e) {
        }
        return view;
    }

    class Holldler {
        TextView name, spec, unit, num;
        Holldler(View v) {
            name = (TextView) v.findViewById(R.id.material_name);
            spec = (TextView) v.findViewById(R.id.material_spec);
            unit = (TextView) v.findViewById(R.id.material_unit);
            num = (TextView) v.findViewById(R.id.material_num);
        }
    }

}
